package com.jaws.demo.schedule.quartz;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.jaws.core.common.log.Log;
import com.jaws.demo.configuration.QuartzConfigProperties;
import com.jaws.demo.schedule.quartz.QuartzTaskUtils;
/**
 * 初始化JOB
 *
 * @author liangqm
 * @date 2017-12-06 10:41:19
 * @since v1.0.0
 */
@Component
public class QuartzInitializer implements CommandLineRunner {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	private QuartzConfigProperties jobConfigProperties;
	
	@Override
	public void run(String... args) throws Exception {
		for(QuartzConfigProperties.QuartzJob job : jobConfigProperties.getJobs()){
			QuartzTaskUtils.createJob(job.getCronExpression(), job.getName(), job.getJobClass(), true);
		}
		logger.info(Log.op("QuartzInitializer.initialize").msg("init finished").toString());
		
	}
}
